package cn.com.b2office.struts2.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.b2office.domain.Article;
import cn.com.b2office.domain.ArticleCategory;
import cn.com.b2office.service.ArticleService;

import com.opensymphony.xwork2.ActionSupport;

public class HelpCenterAction extends ActionSupport {
	private static final long serialVersionUID = 7585921508829852649L;

	private ArticleService articleService = null;

	private List<ArticleCategory> categories = null;

	private List<Article> articles = null;

	private Map<String, List<Article>> articleMap = null;

	private int categoryId = 200;

	public String execute() throws Exception {
		List<Integer> categoryIdList = new ArrayList<Integer>();
		for (int i = 200; i <= 210; i++) {
			categoryIdList.add(i);
		}
		categories = articleService.findCategory(categoryIdList);
		articleMap = new HashMap<String, List<Article>>();
		for (ArticleCategory c : categories) {
			List<Article> list = articleService.findArticle(c.getCategoryId());
			articleMap.put(String.valueOf(c.getCategoryId()), list);
			if (c.getCategoryId() == categoryId)
				articles = list;
		}

		if (categoryId != -1)
			articles = articleService.findArticle(categoryId);
		return SUCCESS;
	}

	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}

	public int getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(int categoryId) {
		this.categoryId = categoryId;
	}

	public List<Article> getArticles() {
		return articles;
	}

	public List<ArticleCategory> getCategories() {
		return categories;
	}

	public Map<String, List<Article>> getArticleMap() {
		return articleMap;
	}

}
